let RouteModel = require('../model/ControllerModel')
const { evaluateAPI } = require('../configure')

class Factor extends RouteModel {

  constructor () {
    super()
  }

  // 查询全量因素列表
  async index (ctx, next) {
    let data = ctx.query;
    let result = await this.request({
      method: "POST",
      url: `${evaluateAPI}/estimate/queryAllQuestions`,
      body: data
    }, ctx.query.traceId);
    result && ctx.$success(result)
  }

  // 更新因素
  async update (ctx, next) {
    let data = ctx.request.fields,
        factorId = ctx.params.factor;
    let result = await this.request({
      method: "POST",
      url: `${evaluateAPI}/estimate/updateFactorInfo`,
      body: Object.assign(data, {'factorId': factorId})
    }, ctx.query.traceId);
    result && ctx.$success(result)
  }

  // 删除因素
  async deleteFactor (ctx, next) {
    let data = ctx.request.fields;
    let result = await this.request({
      method: "POST",
      url: `${evaluateAPI}/estimate/deleteFactorById`,
      body: {'factorIds': [data.factorId]}
    }, ctx.query.traceId);
    result && ctx.$success(result)
  }
}

module.exports = Factor
